trigger WriteSSYActivityExecution on In_Store_Visit__c (after insert) {
  /*  List<SSYActivityExecutionTracking__c> ssyList=new List<SSYActivityExecutionTracking__c>();
    
    List<String> MonthList=new List<String>();
    List<String> YearList=new List<String>();
    List<Date> DateList=new List<Date>();
    
    String strM='',strY='';
    for(In_Store_Visit__c st:trigger.new)
    {
        DateTime dt=st.Start_Time__c;
        
        if(strM!='')
            strM+='or';
            
        strM+='Month__c=\''+String.valueOf(dt.Month())+'\'';
        
        if(strY!='')
            strY+='or';
            
        strY+='Year__c=\''+String.valueOf(dt.Year())+'\'';
        
        Date d=Date.newInstance(dt.year(),dt.month(),1);
        //trigger.new[0].addError(String.valueof(dt.month()));
        //if(dt.month<10)
        MonthList.add(String.valueof(dt.month()));
        YearList.add(String.valueOf(dt.year()));
        DateList.add(d);
    }
    
    //List<Sales_Target__c> targetList=[select TotalValue__c,Month__c,Year__c,NextSales__c,Sales_Target_Type__c from Sales_Target__c 
                                        //where NextSales__c=:UserInfo.getUserId() and Month__c in: MonthList
                                        //and Year__c in:YearList and Sales_Target_Type__c='SSY Activity Outlet Number'];
    
    String sql='select TotalValue__c,Month__c,Year__c,NextSales__c,Sales_Target_Type__c from Sales_Target__c where NextSales__c=\''+UserInfo.getUserId()+'\' and ('+strM+') and ('+strY+') and Sales_Target_Type__c=\'SSY Activity Outlet Number\'';
   // trigger.new[0].addError(sql);
    List<Sales_Target__c> targetList=DataBase.query(sql);
   
    List<SSYActivityExecutionTracking__c> inSvList=[select TSR__c,OutletName__c,SalesMonth__c,SSYTarget__c
     from SSYActivityExecutionTracking__c where TSR__c=:UserInfo.getUserId() and SalesMonth__c in:DateList];
     
     Map<Id,Date> mapList=new Map<Id,Date>();
     Map<Date,String> mapList2=new Map<Date,String>();
     
     if(targetList.size()>0)//写入SalesTarget
     {
         for(Sales_Target__c i:targetList)
         {
            Date d=Date.newInstance(Integer.valueOf(i.year__c),Integer.valueOf(i.Month__c),1);
            //trigger.new[0].addError(i.Month__c+'dddd'+String.valueof(i.TotalValue__c));
            mapList2.put(d,String.valueof(i.TotalValue__c));
            //trigger.new[0].addError(m);
         }
     }
     else
     {
        for(In_Store_Visit__c st:trigger.new)
        {
            DateTime dt=st.Start_Time__c;
            Date d=Date.newInstance(dt.year(),dt.month(),1);
            mapList2.put(d,String.valueof(0));
        }
     }
         
     if(inSvList!=NULL && inSvList.size()>0)
     {
         for(SSYActivityExecutionTracking__c ssy:inSvList)
         {
            mapList.put(ssy.OutletName__c,ssy.SalesMonth__c);
         }
         
         for(In_Store_Visit__c isvisit:trigger.new)
        {
            if(isvisit.SSYActivityAchievement__c)
            {
                if(!mapList.containsKey(isvisit.OutletName_del__c))
                {
                    DateTime dt=isvisit.Start_Time__c;
                    Date d=Date.newInstance(dt.year(),dt.month(),1);
                    Integer TotalNum=Integer.valueof(mapList2.get(d));
                    
                    SSYActivityExecutionTracking__c sae=new SSYActivityExecutionTracking__c();
                    sae.OutletName__c=isvisit.OutletName_del__c;
                    sae.ExecutedSSY__c=1;
                    if(inSvList!=NULL && inSvList.size()>0)//如果同一个TSR在SSYActivityExecutionTracking__c里有值说明已经存入了SalesTarget
                        sae.SSYTarget__c=0;
                    else
                        sae.SSYTarget__c=TotalNum;
                    
                    sae.TSR__c=UserInfo.getUserId();
                    sae.SalesMonth__c=Date.newInstance(dt.year(),dt.month(),1);
                    ssyList.add(sae);
                    //sae
                }
            }
        }
     }
     else
     {
        for(In_Store_Visit__c isvisit:trigger.new)
        {
            if(isvisit.SSYActivityAchievement__c)
            {
                DateTime dt=isvisit.Start_Time__c;
                //trigger.new[0].addError(String.valueof(dt.month()));
                Date d=Date.newInstance(dt.year(),dt.month(),1);
                Integer TotalNum=Integer.valueof(mapList2.get(d));
                //Integer TotalNum=Integer.valueof(mapList2.get(String.valueOf(dt.month())));
                    
                SSYActivityExecutionTracking__c sae=new SSYActivityExecutionTracking__c();
                sae.OutletName__c=isvisit.OutletName_del__c;
                sae.ExecutedSSY__c=1;
                sae.SSYTarget__c=TotalNum;
                sae.TSR__c=UserInfo.getUserId();
                sae.SalesMonth__c=Date.newInstance(dt.year(),dt.month(),1);
                ssyList.add(sae);
            }
        }
     }
     
     insert ssyList;

 */    
}